package rsj.exception;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.ThinkException;
import common.exec.BaseException;
import common.exec.RsjIllegalArgueException;
import common.util.BoxUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理
 *
 * @author yuanqinglong
 * @since 2021/8/17 17:20
 */
@RestControllerAdvice
public class MyExceptionAdvice {

    private static final Logger logger = LoggerFactory.getLogger(MyExceptionAdvice.class);

    /**
     * RsjIllegalArgueException
     *
     * @param exception 异常
     * @param param     参数
     * @return 封装错误返回数据
     */
    @ExceptionHandler(RsjIllegalArgueException.class)
    public Box rsjIllegalArgueException(RsjIllegalArgueException exception, Box param) {
        return BoxUtil.errorBox(param, exception.getMessage());
    }


    /**
     * BaseException
     *
     * @param exception 异常
     * @param param     参数
     * @return 封装错误返回数据
     */
    @ExceptionHandler(BaseException.class)
    public Box baseException(BaseException exception, Box param) {
        return BoxUtil.errorBox(param, exception.getMessage());
    }

    /**
     * ThinkException
     *
     * @param exception 异常
     * @param param     参数
     * @return 封装错误返回数据
     */
    @ExceptionHandler(ThinkException.class)
    public Box thinkException(ThinkException exception, Box param) {
        return BoxUtil.errorBox(param, "服务器忙");
    }


    /**
     * Exception
     *
     * @param exception 异常
     * @param param     参数
     * @return 封装错误返回数据
     */
    @ExceptionHandler(Exception.class)
    public Box exception(Exception exception, Box param) {
        return BoxUtil.errorBox(param, "服务器忙");
    }


}
